package net.sxnic.workflow.node;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import net.sxinfo.core.entity.AbstractEntity;
import net.sxnic.comm.coe.Coe;
import net.sxnic.workflow.handler.Handler;
import net.sxnic.workflow.pd.Pd;
import net.sxnic.workflow.transition.Transition;

import org.hibernate.annotations.BatchSize;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

/**
 * 节点定义实体
 * @author 孙宇飞
 *
 */
@Entity
@Table(name = "wf_node")
@BatchSize(size = 10)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Node extends AbstractEntity{

	private static final long serialVersionUID = -2228219316605197905L;
	
	public static final String CATE_TASK ="task";
	
	public static final String CATE_START ="start";
	
	public static final String CATE_END ="end";

	/**
	 * 节点名称
	 */
	@Column(nullable=false)
	private String name;
	
	/**
	 * 别名 niban=拟办 或 收文拟办 chengban = 处室承办 或 厅室承办 或承办
	 */
	private String alias;
	
	//start开始节点 end结束节点 task普通任务节点 sub子流程节点 out外部流程节点
	private String cate;
	
	/**
	 * 办理人定义 如 user:gal,sgy;group:000,001;role:office,docManager;special:chuanyue   special表示特殊处理 
	 */
	private String assignee;
	
	/**
	 * 后续节点定义
	 */
	@Column(name="nextnode_")
	private String nextNode;
	
	/**
	 * 要转到的JSP页面
	 */
	@Column(name="jsp_")
	private String jsp;
	
	/**
	 * 图形定义
	 */
	@Column(name="chart_")
	private String chart;
	
	/**
	 * 流程图后续节点 类似nextNode，如果有多个的话，第一个为主，其余为辅 
	 */
	private String wfChartNextNode;
	
	
	/**
	 * 验证脚本
	 */
	@Column(name="validate_")
	private String validate;
	
	/**
	 * 按钮定义
	 */
	@Column(name="buttons_")
	private String buttons;
	
	/**
	 * 在图形显示中的编号、序号
	 */
	private String chartNum;
	
	/**
	 * 在图形显示中的top位置
	 */
	@Column(name="top_")
	private long top;
	
	/**
	 * 在图形显示中的left位置
	 */
	@Column(name="left_")
	private long left;
	
	/**
	 * 提醒方式 system系统设置 pd设置 sms单独短信通知 msg站内消息
	 */
	@Column(length=10)
	private String remindCate;
	
	/**
	 * 办理时限(Day:10十天 or H:10十小时)
	 */
	private String timeLimited;
	
	/**
	 * 申报过程状态码
	 */
	private String statusCode;
	
	/**
	 * 申报过程状态名
	 */
	private String statusName;
	
	private String str1;
	private String str2;
	private String str3;
	private String str4;
	private String str5;
	
	@OneToMany
	@Cascade(value = { CascadeType.ALL })
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	private Set<Coe> coes;
	
	@OneToMany
	@Cascade(value = { CascadeType.ALL })
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	private List<Handler> handlers;
	
	@OneToMany
	@Cascade(value = { CascadeType.ALL })
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	private List<Transition> transitions;
	
	@ManyToOne
	@Cascade(value = { CascadeType.REFRESH})
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)	
	private Pd pd;	

	public Node() {
		super();		
		remindCate = "system";
		timeLimited = "";
		cate = CATE_TASK;		
		coes = new LinkedHashSet<Coe>();
		handlers = new ArrayList<Handler>();
		transitions = new ArrayList<Transition>();
	}
		
	
	public Map<String,String> getCoeMap(){
		return null;
	}
	
	public String getCoeProperty(String key){
		for(Coe c:coes){
			if(key.endsWith(c.getKey())){
				return c.getValue();
			}
		}
		
		return "";
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCate() {
		return cate;
	}

	public void setCate(String cate) {
		this.cate = cate;
	}

	public Set<Coe> getCoes() {
		return coes;
	}

	public void setCoes(Set<Coe> coes) {
		this.coes = coes;
	}


	public Pd getPd() {
		return pd;
	}

	public void setPd(Pd pd) {
		this.pd = pd;
	}

	public String getRemindCate() {
		return remindCate;
	}

	public void setRemindCate(String remindCate) {
		this.remindCate = remindCate;
	}

	public String getTimeLimited() {
		return timeLimited;
	}

	public void setTimeLimited(String timeLimited) {
		this.timeLimited = timeLimited;
	}

	public String getChartNum() {
		return chartNum;
	}

	public void setChartNum(String chartNum) {
		this.chartNum = chartNum;
	}

	public long getTop() {
		return top;
	}

	public void setTop(long top) {
		this.top = top;
	}

	public long getLeft() {
		return left;
	}

	public void setLeft(long left) {
		this.left = left;
	}

	public String getNextNode() {
		return nextNode;
	}

	public void setNextNode(String nextNode) {
		this.nextNode = nextNode;
	}

	public String getJsp() {
		return jsp;
	}

	public void setJsp(String jsp) {
		this.jsp = jsp;
	}

	public String getChart() {
		return chart;
	}

	public void setChart(String chart) {
		this.chart = chart;
	}

	public String getWfChartNextNode() {
		return wfChartNextNode;
	}

	public void setWfChartNextNode(String wfChartNextNode) {
		this.wfChartNextNode = wfChartNextNode;
	}

	public String getValidate() {
		return validate;
	}

	public void setValidate(String validate) {
		this.validate = validate;
	}
	
	public boolean needValidateSignPwd(){
		return true;
	}


	public String getButtons() {
		return buttons;
	}


	public void setButtons(String buttons) {
		this.buttons = buttons;
	}


	public String getAssignee() {
		return assignee;
	}


	public void setAssignee(String assignee) {
		this.assignee = assignee;
	}


	public List<Handler> getHandlers() {
		return handlers;
	}


	public void setHandlers(List<Handler> handlers) {
		this.handlers = handlers;
	}


	public String getAlias() {
		return alias;
	}


	public void setAlias(String alias) {
		this.alias = alias;
	}

	public String getStr1() {
		return str1;
	}


	public void setStr1(String str1) {
		this.str1 = str1;
	}


	public String getStr2() {
		return str2;
	}


	public void setStr2(String str2) {
		this.str2 = str2;
	}


	public String getStr3() {
		return str3;
	}


	public void setStr3(String str3) {
		this.str3 = str3;
	}


	public String getStr4() {
		return str4;
	}


	public void setStr4(String str4) {
		this.str4 = str4;
	}


	public String getStr5() {
		return str5;
	}


	public void setStr5(String str5) {
		this.str5 = str5;
	}


	public List<Transition> getTransitions() {
		return transitions;
	}


	public void setTransitions(List<Transition> transitions) {
		this.transitions = transitions;
	}


	public String getStatusCode() {
		return statusCode;
	}


	public void setStatusCode(String statusCode) {
		this.statusCode = statusCode;
	}


	public String getStatusName() {
		return statusName;
	}


	public void setStatusName(String statusName) {
		this.statusName = statusName;
	}
	
	
	
}
